package com.taojin.shoppinginterest.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.lidroid.xutils.BitmapUtils;
import com.lidroid.xutils.ViewUtils;
import com.lidroid.xutils.view.annotation.ViewInject;
import com.taojin.shoppinginterest.R;
import com.taojin.shoppinginterest.bean.Favorite;
import com.taojin.shoppinginterest.utils.BitmapHelper;

import java.util.List;

/**
 * Created by T400 on 15-5-12.
 */
public class FavoriteFragmentAdapter extends AppAdapter<Favorite> {

    private BitmapUtils bitmapUtils;

    public FavoriteFragmentAdapter(List<Favorite> list, Context context) {
        super(list, context);
        bitmapUtils = BitmapHelper.getInstance().getBitmapUtils(context, R.mipmap.icon, R.mipmap.icon);
    }

    @Override
    public View createItemView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder = null;
        if (convertView == null) {
            convertView = inflater.inflate(R.layout.item_favoritefragment, null);
            viewHolder = new ViewHolder(convertView);
            convertView.setTag(viewHolder);

        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }

        bitmapUtils.display(viewHolder.img_url, list.get(position).getImg_url());
        bitmapUtils.display(viewHolder.logo, list.get(position).getLogo());

        viewHolder.shop_name.setText(list.get(position).getShop_name());
        viewHolder.name.setText(list.get(position).getName());
        viewHolder.cate.setText(list.get(position).getCate());
        viewHolder.distance.setText(list.get(position).getDistance());
        viewHolder.time.setText(list.get(position).getTime());
        viewHolder.youhui.setText(list.get(position).getYouhui());

        return convertView;
    }


    private static class ViewHolder {
        @ViewInject(R.id.img_url_item_favofragment)
        private ImageView img_url;
        @ViewInject(R.id.shop_name_item_favofragment)
        private TextView shop_name;
        @ViewInject(R.id.cate_item_favofragment)
        private TextView cate;
        @ViewInject(R.id.img_logo_item_favofragment)
        private ImageView logo;
        @ViewInject(R.id.name_item_favofragment)
        private TextView name;
        @ViewInject(R.id.youhui_item_favofragment)
        private TextView youhui;
        @ViewInject(R.id.time_item_favofragment)
        private TextView time;
        @ViewInject(R.id.distance_item_favofragment)
        private TextView distance;

        public ViewHolder(View convertView) {
            ViewUtils.inject(this, convertView);
        }
    }

}
